package com.fortune.service.impl;

import com.faneui.common.exception.BusinessException;
import com.faneui.common.utils.DateFormatUtils;
import com.faneui.common.utils.ListUtils;
import com.fortune.dal.dao.FundMarketDAO;
import com.fortune.dal.model.FundMarket;
import com.fortune.service.FundSyCalculateService;
import com.fortune.service.WorkDayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;

@Service
public class FundSyCalculateServiceImpl implements FundSyCalculateService {

    @Autowired
    private FundMarketDAO fundMarketDAO ;

    @Autowired
    private WorkDayService workDayService;

    @Override
    public void calculateFundSy(FundMarket fundMarket) throws BusinessException {
        SimpleDateFormat sdf = DateFormatUtils.yyyyMMdd ;
        try{
//            FundMarket market = fundMarketDAO.queryById(fundMarket.getId()) ;
//            String occurDate = market.getOccurDate() ;
//            String lastDate = workDayService.getLastWorkDay(occurDate) ;
//
//            Calendar calendar = Calendar.getInstance() ;
//            calendar.setTime(sdf.parse(occurDate));
//            do {
//                calendar.add(Calendar.DATE, -1);
//                date = DateFormatUtils.yyyyMMdd.format(calendar.getTime());
//            } while (isWorkDay(date));
//            FundMarket param = new FundMarket();
//            param.setFundCode(market.getFundCode());
//            param.setOccurDate(lastDate);
//            List<FundMarket> lastMarkets = fundMarketDAO.queryByModel(param) ;
//            BigDecimal lastNav = market.getNav() ;
//            if(ListUtils.isNotEmpty(lastMarkets)) {
//                lastNav = lastMarkets.get(0).getNav() ;
//            }
//


        }catch (Exception ex) {

        }

    }

    @Override
    public void calculateJzFundSy() throws BusinessException {

    }

    @Override
    public void calculateFundJzCompare() throws BusinessException {

    }
}
